<template>
	<view class='selectBox'>
		<u-radio-group v-model="radioValue" :disabled="disabled" :wrap="wrap">
			<u-radio 
				@change="change" 
				v-for="(item, index) in dictOptions" :key="index" 
				:name="item.itemValue"
				:disabled="item.disabled"
			>
				{{ item.itemName }}
			</u-radio>
		</u-radio-group>
	</view>
</template>
<script>
/*
	<dictRadioTag v-model="model.providerRelation" :disabled="disabled" dictCode="infooffer_oldrelation"></dictRadioTag>

	import dictRadioTag from '@/components/dict/dictRadioTag.vue'

*/
	import { getDict } from '@/utils/utils'
	export default {
		name: 'DictRadioTag',
		model: {
			prop: 'value',
			event: 'change'
		},
		props: {
			dictCode: { // 必传 词典标识：如 sex
				type: String,
				default: ''
			},
			wrap: { // 是否占一行
				type: Boolean,
				default: true
			},
			disabled: {
				type: Boolean,
				default: false
			},
			value: [String, Number]
		},
		data() {
			return {
				dictOptions: []
			}
		},
		computed: {
			radioValue: {
				get(){
					if(this.value || this.value === 0 || this.value === '0'){
						return this.dictOptions.find(res=> res.itemValue == this.value)?.itemValue
					}
				},
				set(val){
					return this.dictOptions.find(res=> res.itemName == val)?.itemValue
				}
			}
		},
		watch: {
			dictCode: {
				immediate: true,
				handler() {
					this.initDictData()
				}
			}
		},
		created() {},
		methods: {
			initDictData() {
				this.dictOptions = getDict(this.dictCode,this)
			},
			change(e) {
				this.$emit('change', e)
			}
		}
	}
</script>

<style scoped lang="scss">
	.selectBox{
		width: 90vw;
	}
	.u-radio{
		align-items: baseline;
		line-height: 2;
	}
</style>
